﻿using System.Collections.Generic;
using System.Data;
using System.Text;
using PPI.Data;
using PPI.Entities;
using PPI.Entities.Interface;
using PPI.Mobile;
using VMind.Global;

namespace PPI.ServiceLogic
{
    public class LUtility : IMobileTable
    {
        public static List<EUtility> SelectAllIdName(string connectionKey)
        {
            List<EUtility> _UtilityList = new List<EUtility>();
            EUtility _Utility;

            DataSet ds = DUtility.SelectAllIdName(connectionKey);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                _Utility = new EUtility();
                _Utility.UtilityId = ConvertHelper.ToInt32(dr["UtilityId"]);
                _Utility.Name = ConvertHelper.Tostring(dr["Name"]);
                _UtilityList.Add(_Utility);
            }
            return _UtilityList;
        }

        public List<EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            listQueries.Add(new EMobileQuery("Delete tb_Utility"));
            DataTable dt = DUtility.SelectAllIdName(connectionKey).Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                listQueries.Add(new EMobileQuery("insert into tb_Utility values (" + ConvertHelper.ToInt32(dr["UtilityId"]) + ",'" + ConvertHelper.Tostring(dr["Name"]) + "')"));
            }
            return listQueries;

        }
    }
}
